package cn.da.shuai.cool.system.api.controller;

import cn.da.shuai.cool.common.entity.R;
import cn.da.shuai.cool.system.model.entity.dept.CoolDept;
import cn.da.shuai.cool.system.model.entity.dept.SearchDeptVo;
import cn.da.shuai.cool.system.model.entity.dept.UpdateDeptVo;
import cn.da.shuai.cool.system.model.entity.dept.DeptTreeVo;
import cn.da.shuai.cool.system.service.service.ICoolDeptService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dept")
@Tag(name = "部门管理", description = "部门管理相关接口")
public class CoolDeptController {

    @Autowired
    private ICoolDeptService departmentService;

    @PostMapping("/list")
    @Operation(summary = "查询部门列表", description = "根据条件查询部门列表")
    public R<List<CoolDept>> list(@RequestBody SearchDeptVo searchDeptVo) {
        return R.ok(departmentService.listDepartments(searchDeptVo));
    }

    @GetMapping("/{id}")
    @Operation(summary = "获取部门详细信息", description = "根据部门ID获取部门详细信息")
    public R<CoolDept> getInfo(@PathVariable("id") Long id) {
        return R.ok(departmentService.getById(id));
    }

    @PostMapping
    @Operation(summary = "新增部门", description = "新增部门信息")
    public R<Boolean> add(@RequestBody UpdateDeptVo dept) {
        return R.ok(departmentService.addDepartment(dept));
    }

    @PutMapping
    @Operation(summary = "修改部门", description = "修改部门信息")
    public R<Boolean> edit(@RequestBody UpdateDeptVo dept) {
        return R.ok(departmentService.updateDepartment(dept));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除部门", description = "删除部门信息")
    public R<Boolean> remove(@PathVariable Long id) {
        return R.ok(departmentService.removeById(id));
    }

    @GetMapping("/tree")
    @Operation(summary = "获取部门树", description = "获取部门的树形结构")
    public R<List<DeptTreeVo>> getDepartmentTree() {
        return R.ok(departmentService.getDepartmentTree());
    }
}